package com.pc.service.Impl;

import com.pc.mapper.UserAccountMapper;
import com.pc.pojo.UserAccount;
import com.pc.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

@Service
public class LoginServiceImpl implements LoginService {

    @Autowired
    UserAccountMapper userAccountMapper;

    @Autowired
    PasswordEncoder passwordEncoder;

    @Override
    public void delete(long userId) {
        userAccountMapper.delete(userId);
    }

    @Override
    public void register(UserAccount userAccount) {

        String password = userAccount.getPassword();
        String encode = passwordEncoder.encode(password);
        userAccount.setPassword(encode);
        userAccountMapper.register(userAccount);

        Long userId = userAccount.getUserId();

        userAccountMapper.insertUserRole(userId,1);
    }
}
